package st.business.tepth.business.goodscheck;


import com.alibaba.fastjson.JSON;
import com.chad.library.adapter.base.entity.MultiItemEntity;

import java.util.ArrayList;
import java.util.List;

import st.business.tepth.business.bean.MaterialCheckBean;
import st.business.tepth.business.bean.PickGoods;
import st.business.tepth.business.bean.post.IDBean;
import st.business.tepth.business.goodscheck.entity.Level0;
import st.business.tepth.business.goodscheck.entity.Level1;

/**
 * @author zhangyu
 * @date 2019/4/24
 */
public class GoodsCheckConvert {
    public List<MultiItemEntity> convertToEntity(List<MaterialCheckBean> list) {
        List<MultiItemEntity> entities = new ArrayList<>();
        if (list != null) {
            for (MaterialCheckBean materialWaitApplyBean : list) {
                List<Level1> subItems = new ArrayList<>();
                Level0 level0 = new Level0(materialWaitApplyBean);
                List<PickGoods> goodsBeanList = materialWaitApplyBean.getParts();
                if (goodsBeanList != null) {
                    for (int j = 0, size = goodsBeanList.size(); j < size; j++) {
                        subItems.add(new Level1(goodsBeanList.get(j)));
                    }
                }
                level0.setSubItems(subItems);
                entities.add(level0);
            }
        }
        return entities;
    }

    public String convertToIDBeanString(MaterialCheckBean bean) {
        List<IDBean> idBeans = new ArrayList<>();
        if (bean != null) {
            List<PickGoods> pickGoods = bean.getParts();
            if (pickGoods != null) {
                for (PickGoods goods : pickGoods) {
                    idBeans.add(new IDBean(goods.getId(), goods.getValue()));
                }
            }
        }
        return JSON.toJSONString(idBeans);
    }
}
